package com.example.mbl.controller;

import com.example.mbl.entity.News;
import com.example.mbl.interceptor.AppToken;
import com.example.mbl.result.PageResult;
import com.example.mbl.result.WebRestResult;
import com.example.mbl.result.business.NewsPageResult;
import com.example.mbl.result.business.NewsResult;
import com.example.mbl.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("News")
public class NewsController {
    @Autowired
    private NewsService newsService;

    @AppToken
    @PostMapping("addNews")
    public WebRestResult addNews(@RequestBody News news){
        WebRestResult result = newsService.addNews(news);
        return result;
    }

    @AppToken
    @PostMapping("deleteNews")
    public WebRestResult deleteNews(@RequestBody News news){
        WebRestResult result = newsService.deleteNews(news);
        return result;
    }

    @AppToken
    @PostMapping("updateNews")
    public WebRestResult updateNews(@RequestBody News news){
        WebRestResult result = newsService.updateNews(news);
        return result;
    }

    @AppToken
    @PostMapping("setTopNews")
    public WebRestResult setTopNews(@RequestBody News news){
        WebRestResult result = newsService.setTopNews(news);
        return result;
    }

    @GetMapping("getNewsList")
    public PageResult<NewsPageResult> getNewsList(String newstype,String newsdate,String newstitle,int page,int pagesize){
        PageResult<NewsPageResult> result = newsService.getNewsList(newstype,newsdate,newstitle,page,pagesize);
        return result;
    }

    @GetMapping("getNewsItem")
    public NewsResult getNewsItem(String newsid){
        NewsResult result = newsService.getNewsItem(newsid);
        return result;
    }

    @AppToken
    @PostMapping("setNewsVisible")
    public WebRestResult setNewsVisible(@RequestBody News news){
        WebRestResult result = newsService.setNewsVisible(news);
        return result;
    }
}
